<template>
  <!-- 我领用的资产 -->
  <div class="myCollecting">

    <!-- 资产列表 组件 -->
    <Asset @go-detail="handleGoAssetDetail" @go-operate="handleOperate" :assetList="assetList" />

    <div class="bgc"></div>
  </div>
</template>

<script>
import { OPERATE_TYPES, EDIT_TYPES, COMMON_TYPES } from '@/constant';
import Asset from '@/components/Asset';
import titleMixins from '@/mixins/title';

export default {
  name: 'MyCollecting',
  mixins: [titleMixins],
  components: {
    Asset
  },
  props: ['$type'],
  data () {
    return {
      assetList: [] // 资产列表
    };
  },
  methods: {
    // 操作
    handleOperate (operate, id, re_id) {
      let query = {
        operate,
        f_id: id,
        id: re_id,
        edit: EDIT_TYPES.CREATE,
        dept_id: this.$route.query.dept_id || ''
      };
      switch (operate) {
        case OPERATE_TYPES.REPAIR:
          if (this.$type === COMMON_TYPES.MY) {
            query.title = '报修';
            query.type = COMMON_TYPES.MY;
          } else if (this.$type === COMMON_TYPES.DEPARTMENT) {
            query.title = '报修';
            query.type = COMMON_TYPES.DEPARTMENT;
          }
          this.$router.push({
            name: 'repairs-form',
            query
          });
          break;

        case OPERATE_TYPES.TRANSFER:
          if (this.$type === COMMON_TYPES.MY) {
            query.title = '转移';
            query.type = COMMON_TYPES.MY;
          } else if (this.$type === COMMON_TYPES.DEPARTMENT) {
            query.title = '转移';
            query.type = COMMON_TYPES.DEPARTMENT;
          }
          this.$router.push({
            name: 'transfer-form',
            query
          });
          break;

        case OPERATE_TYPES.RETURN:
          if (this.$type === COMMON_TYPES.MY) {
            query.title = '退还';
            query.type = COMMON_TYPES.MY;
          } else if (this.$type === COMMON_TYPES.DEPARTMENT) {
            query.title = '退还';
            query.type = COMMON_TYPES.DEPARTMENT;
          }
          this.$router.push({
            name: 'return-form',
            query
          });
          break;

        case OPERATE_TYPES.LOSS:
          if (this.$type === COMMON_TYPES.MY) {
            query.title = '报失';
            query.type = COMMON_TYPES.MY;
          } else if (this.$type === COMMON_TYPES.DEPARTMENT) {
            query.title = '报失';
            query.type = COMMON_TYPES.DEPARTMENT;
          }
          this.$router.push({
            name: 'loss-form',
            query
          });
          break;
      }
    },
    // 前往资产详情
    handleGoAssetDetail (id) {
      this.$router.push({
        name: 'asset-detail',
        query: {
          id
        }
      });
    },
    // 获取我的资产列表
    getAsset () {
      this.$api.postReceiceMyAsset().then(res => {
        if (res.code === 0) {
          this.assetList = res.result;
        }
      });
    },
    // 获取部门资产列表
    getDeptAsset () {
      let params = {
        dept_id: this.$route.query.dept_id
      };
      this.$api.getReceiceDeptAsset(params).then(res => {
        if (res.code === 0) {
          this.assetList = res.result;
        }
      });
    }
  },
  created () {
    if (this.$type === COMMON_TYPES.MY) {
      this.getAsset(); // 获取我的资产列表;
    } else if (this.$type === COMMON_TYPES.DEPARTMENT) {
      this.getDeptAsset();// 获取部门资产列表
    }
  }
};
</script>

<style lang="scss" scoped>
.myCollecting {
  font-size: 14px;
  .bgc {
    height: 50px;
    background-color: #f8f9fd;
  }
}
</style>
